package everyday;

import org.junit.jupiter.api.Test;
import tool.s;

import java.util.*;

public class T1125 {
    public int[] smallestSufficientTeam(String[] req_skills, List<List<String>> people) {
        List<String> req = new ArrayList<>();
        Collections.addAll(req, req_skills);
        Map<Integer, List<Integer>> map = new HashMap<>();
        map.put(0, new ArrayList<>());
        for (int i = 0; i < people.size(); i++) {
            List<String> list = people.get(i);
            int has_skills = 0;
            int d;
            for (String str : list) {
                d = req.indexOf(str);
                has_skills = has_skills | (1 << d);
            }
            int tmp_key;
            List<Integer> tmp_list;
            Set<Integer> set=new HashSet<>(map.keySet());
            for (int key : set) {
                tmp_key=key|has_skills;
                tmp_list= new ArrayList<>(map.get(key));
                tmp_list.add(i);
                if (!map.containsKey(tmp_key) || tmp_list.size()<map.get(tmp_key).size()  ) {
                    map.put(tmp_key, tmp_list);
                }
            }
        }
        List<Integer> list=map.get((int)Math.pow(2,req_skills.length)-1);
        return list.stream().mapToInt(i->i).toArray();
    }
    @Test
    public void test() {
        String [] req={"java","nodejs","reactjs"};
        List<List<String>> people=new ArrayList<>();
        people.add(new ArrayList<String>(){{add("java");}});
        people.add(new ArrayList<String>(){{add("nodejs");}});
        people.add(new ArrayList<String>(){{add("nodejs");add("reactjs");}});
        s.print(smallestSufficientTeam(req,people));
    }
}
